package com.dinggao.crossgo.core.observer;

import java.util.ArrayList;

/**
 * created by mapingan on 2018/8/10.
 */
public class ConcreteObservableA implements PrivateObservable {
    private ArrayList<PrivateObserver> privateObservers;

    @Override
    public void addObserver(PrivateObserver privateObserver) {
        if (privateObservers == null) {
            privateObservers = new ArrayList<>();
        }
        privateObservers.add(privateObserver);
    }

    @Override
    public void removeObserver(PrivateObserver privateObserver) {
        if (privateObservers == null || privateObservers.size() <= 0) {
            return;
        }
        privateObservers.remove(privateObserver);
    }

    @Override
    public void notifyObservers(Object obj) {
        if (privateObservers == null || privateObservers.size() <= 0) {
            return;
        }
        for (PrivateObserver privateObserver : privateObservers) {
            privateObserver.update(obj);
        }
    }

}
